<?php
namespace Controller;
use Kuyuan\WqCore\controller\Controller;
use Model\ReadNoticeModel;
use Model\SettingModel;

/**
 * 阅读系统公告
 * Class ReadNotice
 * @package Controller
 */
class ReadNotice extends Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 阅读记录
     * @param int $_read_time 阅读时间
     * @return mixed
     */
    public function read()
    {
        $_read_time = SettingModel::where("uniacid",$this->_uniacid)->value("notice_time");
        if($this->value("id")) {
            $_result = ReadNoticeModel::where("uniacid",$this->_uniacid)
                ->where("uid",$this->_uid)
                ->update(array("time"=>$_read_time));
        } else {
            $_result =  ReadNoticeModel::create(array(
                "uniacid" => $this->_uniacid,
                "uid" => $this->_uid,
                "time" => $_read_time
            ));
        }
        return $_result;
    }

    /**
     * 获取指定值
     * @param $_field
     * @return mixed
     */
    public function value($_field)
    {
        return ReadNoticeModel::where("uniacid",$this->_uniacid)
            ->where("uid",$this->_uid)
            ->value($_field);
    }
}